import Vue from 'vue'//引入vue
import VueRouter from 'vue-router'//引入路由
Vue.use(VueRouter);//挂在路由组件
import state from '@/store/store'//引入vuex
import Index from '../components/index.vue'//首页
import BookDetails from '@/components/BookDetails.vue';//书本详情
import aishuben from '@/components/aishuben.vue';//ai生成测试（没用）
import sousuo from '@/components/sousuo.vue';//搜素
import Zuozhe from '@/components/Zuozhe.vue';//作家页
import Writer from '@/components/writer.vue';//成为作家
import person from '@/components/my/person.vue';//个人
import perusal from '@/components/perusal.vue';//阅读
import shujia from '@/components/my/shujia.vue';//收藏
import vip from '@/components/vip.vue';//vip
import thecharts from '@/components/thecharts.vue';//人气榜单
import ShuKu from '@/components/shuku.vue';//书库
import writing from '@/components/zuojia/writing.vue';//作者个人页
import PrivacyAgreement from '@/components/xieyi/PrivacyAgreement.vue';//隐私协议
import HYXY from '@/components/xieyi/HYXY.vue';//会员协议
import UserAgreement from '@/components/xieyi/UserAgreement.vue';//用户协议
import worksAg from '@/components/xieyi/worksAg.vue';//作品签约协议
// import denglu from '@/components/zujian/login.vue'//登录组件
const routes = [
    //路由表示的是url和组件的一一对应的关系，使用path属性表示url路径，使用component属性表示组件
    // {
    //     name: '/Index',//首页
    //     path: '/denglu',
    //     component: denglu
    // },
    {
        name: '/Index',//首页
        path: '/',
        component: Index
    },
    {
        name: '/BookDetails',//书本详情
        path: '/bookDetails/:id',
        component: BookDetails,
    },
    {
        name: '/aishuben',//ai测试
        path: '/aishuben',
        component: aishuben,
    },
    {
        name: '/sousuo',//搜索
        path: '/sousuo',
        component: sousuo,
    },
    {
        name: '/Zuozhe',//作者主页
        path: '/author/:name',
        component: Zuozhe,
    },
    {
        name: '/Writer',//作家主页
        path: '/writer',
        
        component: Writer,
    },
    {
        name: '/person',//个人首页
        path: '/person',
        component: person,
    },
    {
        name: '/perusal',//阅读页
        path: '/perusal/:bookId/:chapterId',
        component:perusal,
    },
    {
        name: '/shujia',//收藏页
        path: '/bookshelf',
        component:shujia,
    },
    {
        name: '/vip',//vip页
        path: '/Recharge',
        component:vip,
    },
    {
        name: '/thecharts',//排行榜
        path: '/thecharts',
        component:thecharts,
    },
    {
        name: '/shuku',//书库
        path: '/shuku/:bookType',
        component:ShuKu,
    },
    {
        name: '/writing',//作家页
        path: '/writing',
        component:writing,
    },
    {
        name: '/ysxy',//隐私协议
        path: '/ysxy',
        component:PrivacyAgreement,
    },
    {
        name: '/yhxy',//用户协议
        path: '/yhxy',
        component:UserAgreement,
    },
    {
        name: '/hyxy',//会员协议
        path: '/hyxy',
        component:HYXY,
    },
    {
        name: '/worksAg',//作品签约协议
        path: '/worksAg',
        component:worksAg,
    }

]

const router = new VueRouter({ routes });
router.beforeEach((to, from, next)=>{
    if(to.name == '/perusal'){
        state.state.navigationalState = false;
    }else{
        state.state.navigationalState = true;
    }
    next();
});
//修改原型对联 的push 
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}


export default router // 导出路由实例
